<template>
    <career-form :errors="errors" :career-id="careerId" @complete="updateCareer"></career-form>
</template>

<script>
    import CareerForm from "./CareerForm";

    export default {
        props: {careerId: {type: Number, required: true}},
        components: {CareerForm}, data() {
            return {errors: {}}
        }, methods: {
            updateCareer(form) {
                axios.put('careers/' + this.careerId, form).then((response) => {
                    this.errors = {};
                    this.$message.success('已成功保存');
                }).catch((error) => {
                    switch (error.response.status) {
                        case 422://表单校验失败
                            this.errors = _.mapValues(error.response.data.errors, (item) => {
                                return item.join(' ');
                            });
                            break;
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>